package com.shi.vueblog.controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.shi.vueblog.common.result.Result;
import com.shi.vueblog.entity.Comment;
import com.shi.vueblog.service.CommentService;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/comment")
public class CommentController {

    @Autowired
    CommentService commentService;

    @RequiresAuthentication//只有登录了才能编辑
    @PostMapping("/add")
    public Result AddComment(@RequestBody Comment comment){
        log.info("request:",comment.getContent());//如果传入的是一个对象 对象属性必须完全一致
        comment.setCreateTime(LocalDateTime.now());
        commentService.save(comment);
        return Result.succ("ok");
    }

    @GetMapping("/all/{id}")
    public  Result allComment(@PathVariable(name = "id") Long id){
        log.info("评论的博客id");
        List<Comment> list = commentService.list(new QueryWrapper<Comment>().eq("blog_id", id));

        return Result.succ("ok",list);
    }
}
